<php> $this->display(tpl('head',true)); </php>
<style>
	.layui-table td, .layui-table th {
	    position: relative;
	    padding: 9px 5px;
	    min-height: 20px;
	    line-height: 20px;
	    font-size: 14px;
	    text-align: center;
	}

	.layui-form-checkbox {
	    height: 20px;
	    line-height: 20px;
	    padding-right: 20px;
	}
	.layui-form-checkbox i {
	    width: 25px;
	    font-size: 18px;
	}
</style>
<fieldset class="layui-elem-field layui-field-title">
  	<legend>文章管理</legend>
</fieldset>
<div class="layui-row">
	<a class="layui-btn layui-btn-sm  layui-btn-warm" href="{{ ADMIN_MODULE_URL  }}/articles/index/">全部</a>
	<a class="layui-btn layui-btn-sm  layui-btn-warm" href="{{ ADMIN_MODULE_URL  }}/articles/index/state_0">未审</a>
	<a class="layui-btn layui-btn-sm  layui-btn-danger" href="{{ ADMIN_MODULE_URL  }}/articles/index/state_1">已审</a>
	<a class="layui-btn layui-btn-sm" href="{{ ADMIN_MODULE_URL  }}/articles/index/is+++recommend_1">已推</a>
</div>
<form class="layui-form" method="post" action="{{ ADMIN_MODULE_URL  }}/articles/batch_edit/">
	<table class="layui-table">
		<thead>
			<tr>
				<th width="20"></th>
				<th>AID</th>
				<th>标题</th>
				<th>所在栏目</th>
				<th>发布人</th>
				<th>浏览量</th>
				<th>评论</th>
				<th>发布时间</th>
				<th>审核</th>
				<th>推荐</th>
				<th>页数</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<foreach array="data">
			<php>
				extract(\\temmoku\\db::from(M_jab.'content')->select('count(*) AS NUM')->where("aid= '{$row['aid']}' ")->row());
				$row['posttime']=date('Y-m-d H:i:s',$row['posttime']);
				$state=$row['state'] ? "checked" :"";
				$is_recommend=$row['is_recommend'] ? "checked" : "";
				$row['all_title']=$row['title'];
				$row['title']=Get_word_strpos($row['title'],'15');
				$url=U(['aid'=>$row['aid'],'cid'=>$row['cid']],M_MODULE);
				$curl=U(['cid'=>$row['cid']],M_MODULE);
			</php>
			<tr>
				<td><input type="checkbox" lay-skin="primary" name="iddb[]" value="{{$row['aid'] }}" /></td>
				<td>{{$row['aid'] }}</td>
				<td title="{{$row['all_title'] }}">
					<a href="{{$url }}" target="_blank">{{$row['title'] }}</a>
				</td>
				<td><a href="{{$curl }}">{{$row['name'] }}</a></td>
				<td>{{$row['username'] }}</td>
				<td>{{$row['clicks'] }}</td>
				<td>{{$row['comment_num'] }}</td>
				<td>{{$row['posttime'] }}</td>
				<td>
					<input {{$state }} lay-skin="switch" lay-filter="state" id="{{$row['aid'] }}" lay-text="已审|待审" type="checkbox" value="1">
				</td>
				<td>
					<input {{$is_recommend }} lay-skin="switch" lay-filter="is_recommend" id="{{$row['aid'] }}" lay-text="已推|未推" type="checkbox" value="1">
				</td>
				<td>{{$NUM }}</td>
				<td width="80">
					<div class="layui-table-cell ">
						<a class="layui-btn layui-btn-sm layui-btn-warm" href="{{ ADMIN_MODULE_URL  }}/articles/edit/aid_{{$row['aid'] }}">编辑</a>
						<a class="layui-btn layui-btn-sm layui-btn-danger" href="{{ ADMIN_MODULE_URL  }}/articles/del/aid_{{$row['aid'] }}">删除</a>
					</div>
				</td>
			</tr>
	</foreach>
		</tbody>
	</table>
	<div class="button">
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('1')">全选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('-1')">反选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('0')">取消选择</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="state" value="1">批量审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="state" value="0">取消审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="is_recommend" value="1">批量推荐</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="is_recommend" value="0">取消推荐</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="del">批量删除</button>
	</div>
</form>
<div class="page">
	{{$Get_Page }}
</div>
<script>
	function all_checkbox_check(type) {
		if(document.getElementsByClassName('layui-form-checkbox') != undefined && document.getElementsByClassName('layui-form-checkbox').length > 0) {
			var class_box = document.getElementsByClassName('layui-form-checkbox');
			var ids = document.getElementsByName('iddb[]');
			if(type == "1") { //全选
				for(var i = 0; i < class_box.length; i++) {
					$(ids[i]).prop("checked", true);
					$(class_box[i]).addClass("layui-form-checked");
				}
			} else if(type == "0") { //全不选
				for(var i = 0; i < class_box.length; i++) {
					$(ids[i]).prop("checked", false);
					$(class_box[i]).removeClass("layui-form-checked");
				}
			} else if(type == "-1") { //反选
				for(var i = 0; i < class_box.length; i++) {
					if(ids[i].checked == true) {
						$(ids[i]).prop("checked", false);
					} else {
						$(ids[i]).prop("checked", true);
					}
					$(class_box[i]).toggleClass("layui-form-checked");
				}
			}
		}
		return false;
	}
	layui.use(['table','form', 'layer'], function() {
		var table = layui.table,form=layui.form,layer = layui.layer;
		form.on('switch(state)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			set({'state': state,'aid': obj.elem.id});

			if(obj.elem.checked == true) {
				layer.tips("已完成审核", obj.othis);
			} else {
				layer.tips("已取消审核", obj.othis);
			}
		});
		form.on('switch(is_recommend)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			set({'is_recommend': state,'aid': obj.elem.id});
			if(obj.elem.checked == true) {
				layer.tips("已完成推荐", obj.othis);
			} else {
				layer.tips("已取消推荐", obj.othis);
			}
		});
		function set(data){
			$.ajax({
				url: "{{ ADMIN_MODULE_URL  }}/articles/batch_edit/",
				type: 'POST',
				data:data,
				dataType: 'json',
				success: function(data) {
					return data;
				}
			})
		}
	});
</script>
<php> $this->display(tpl('foot',true)); </php>
